# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        if root is None:
            return True
        left = [root.left]
        right = [root.right]

        while len(left) != 0 and len(right) != 0:
            if len(left) != len(right):
                return False
            for i in range(len(left)):
                if left[i] is None:
                    if right[-1 * i - 1] is None:
                        continue
                    return False
                if right[-1 * i - 1] is None:
                    return False

                if left[i].val != right[-1 * i - 1].val:
                    return False
            left = self.getLevelNodes(left)
            right = self.getLevelNodes(right)

        return True

    def getLevelNodes(self, arr):
        if arr is None and len(arr):
            return []
        new_arr = []
        for node in arr:
            if node is None:
                continue
            new_arr.append(node.left)
            new_arr.append(node.right)
        return new_arr


if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    r = so.isSymmetric(root)
    print(r)
